package com.dap.commons;

import com.dap.core.context.DapContext;
import org.springframework.beans.factory.support.BeanDefinitionReader;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.test.context.support.AbstractGenericContextLoader;

import com.dap.core.container.DapXmlApplicationContext;
import com.dap.core.context.ContextUtils;

public class ComponentContextLoader extends AbstractGenericContextLoader {
	@Override
	protected BeanDefinitionReader createBeanDefinitionReader(GenericApplicationContext context) {

		//ContextUtils.init();
		DapXmlApplicationContext ctx = new DapXmlApplicationContext(getResourceSuffix());
		context.setParent(ctx);
		ContextUtils.setSpringDapContext(context);
		ContextUtils.setSpringAppContext(context);

		return new XmlBeanDefinitionReader(context);
	}

	@Override
	protected String getResourceSuffix() {
		return DapContext.DAP_ALL_COMPONENT_PATH;
	}

}
